<?php
/**
 * 牌局日志备份和缓存实日志
 * Created by PhpStorm.
 * Keter
 * 2016/8/1
 * @守护进程
 */
class PaijuVisitHandler extends ScriptBase
{
    /**
     * 游戏服保存的牌局日志KEY
     */
    const LOG_NAME = 'cardLog';

    /**
     * 出错备份
     */
    const QUEEN_BACKUP_NAME = 'cardLogBackup';

    /**
     * 当前脚本暂停标志
     * 同类结果为TRUE时则暂停和停止，如1
     */
    const SUSPEND_TAG = 'PAIJU_LOG_HANDLER_SUSPEND'; //暂停

    /**
     * 停止脚本标志
     */
    const STOP_TAG = 'PAIJU_LOG_HANDLER_STOP'; //停止

    /**
     * PHP用牌局日志缓存KEY
     */
    const CACHE_KEY = 'PJL';

    /**
     * 读取数据处理条数  add by tmac
     */
    const CACHE_LIMIT_NUMBER = 1000;

    /**
     * 日志文件大小  add by tmac
     */
    const LOG_FILE_SIZE = 2540000;
    /**
     * 过期时间
     */
    private $_expireTime;

    /**
     * 牌局日志Redis
     */
    protected $paijuRedis;

    /**
     * 逻辑代码
     */
    public function logic()
    {
        set_time_limit(0);
        $this->paijuRedis = $this->redis('visit_log');
        $dataVnums = $this->paijuRedis->keys('VNL:'.'*');
        $i = 0;
        $paijuLog = new PaijuLog();
        $paijuLog->isRedisLog(false);
        foreach( $dataVnums as $v ){
            $fields = array(
                'paiZuID',   'seq',      'time',
                'uids',      'serverID', 'roomID',
                'detail', 'creator','juShu'
            );
            $value = $this->paijuRedis->hMget( $v, $fields );
            $newk  = substr($v, 4);
            $value1 = $this->paijuRedis->hMget( 'V:'.$newk, ['uid'] );
            $this->e('~~~~~~~~~~', $value1);
            $this->e('@@@@@@@@@', $value);
            $this->e($newk, $value);
            if(empty($value)){
                continue;
            }
            $value['creator'] = $value1['uid'];
            $paijuLog->backup2db($value, $newk);
            $this->e('*********', $value);
            $i++;
            if( $i % 10 == 0){
                sleep(1);
            }
        }
        $this->deinitRedis('visit_log');
    }







}
?>